# 使用多阶段构建来优化镜像大小
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app

# 复制项目文件并恢复依赖
COPY *.csproj ./
RUN dotnet restore

# 复制所有源代码
COPY . ./

# 发布应用
RUN dotnet publish -c Release -o out

# 运行时镜像
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app

# 安装必要的包用于HTTPS和证书管理
RUN apt-get update && apt-get install -y \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# 复制发布的应用
COPY --from=build /app/out .

# 创建非root用户
RUN groupadd -r appuser && useradd -r -g appuser appuser
RUN chown -R appuser:appuser /app
USER appuser

# 暴露端口
EXPOSE 5000
EXPOSE 5001

# 设置环境变量
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS=http://+:5000;https://+:5001
ENV ASPNETCORE_HTTPS_PORT=5001

# 启动应用
ENTRYPOINT ["dotnet", "WebRtcProject.dll"] 